
function iPresentation(anime, id)
{
    var div = document.getElementById(id);
    var text = div.innerHTML;
    var arr = text.split('\n');
    var data = [];
    var last = {}; // dummy
    var index = 0;
    for (var i in arr) {
        var line = arr[i];
        if (line.length==0) continue;
        var result;
        if (result = line.match(/^===(.*)/)) {
            last = { takahashi: result[1] }; 
            data.push(last);
        } else if (result = line.match(/^==(.*)/)) {
            last = { title: result[1] }; 
            data.push(last);
            index = 1;
        } else if (result = line.match(/^\s\*(.*)/)) {
            last[index++] = result[1];
        }
    }
    document.body.removeChild(div);

    var width = iBrowse.getWindowWidth();
    var height = iBrowse.getWindowHeight();
    var style = "width:{W}px;height:{H}px";
    style = style.replace(/{W}/, width).replace(/{H}/, height);
    var smallfont = Math.min(width/22, height/15);
    var html = "<div id='main' class='background' style='font-size:{SF}px;{ST}'>"
             + "</div>"
             + "<div id='hidden'></div>";
    html = html.replace(/{SF}/, smallfont).replace(/{ST}/, style);
    document.write(html);
    var main = document.getElementById('main');
    var sideDiv = document.getElementById('hidden');
    var slide = "<div id='{P}' class='slide'>{C}</div>";
    var cur = 0;
    var pages = [];
    _goto(cur);

    function _click()
    {
        anime.add( {element:pages[cur], effect:'fadeout', duration:200} );
        cur++;
        if (cur < data.length) {
            _goto();
        } else {
            cur = 0;
            setTimeout(_goto, 2000);
        }
    }

    function _goto() {
        var index = cur;
        _prepare(index);
        var seq;
        var p = pages[index];
        var d = data[index];
        var dur = d.duration || 500;
        var effect = d.effect || 'easeinout';
        if (effect == 'fadein') {
            seq = [ { element:p, effect:'fadeout', x:0, y:0 },
                    { element:p, effect:'fadein', duration:dur } ];
        } else {
            seq = [ { element:p, effect:'fadein', x:width, y:0 },
                    { element:p, effect:effect, x:0, duration:dur } ];
        }
        anime.addSequence(seq);
    }
 
    function _prepare(index) {
        if (pages[index]) return;
        var info = data[index];
        var contents;
        if (info.takahashi) {
            contents = "<p class='takahashi'>{T}</p>";
            html = slide.replace(/{P}/,index).replace(/{C}/,contents);
            html = html.replace(/{T}/, info.takahashi);
        } else if (info.title) {
            contents = "<p class='title'>{T}</p><div>{I}</div>";
            html = slide.replace(/{P}/,index).replace(/{C}/,contents);
            var items = "<UL>";
            for (var i=1; info[i]; i++) {
                items += "<LI>" + info[i] + "</LI>";
            }
            items += "<UL>";
            html = html.replace(/{T}/, info.title).replace(/{I}/, items);
        }
        sideDiv.innerHTML = html;
        var page = document.getElementById(index);
        sideDiv.removeChild(page);
        main.appendChild(page);
        page.style.left = width + "px";
        page.onclick = _click;
        pages[index] = page;
    }
 
}
